package com.my.springcloud.services;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
@DefaultProperties(defaultFallback = "globalFallBack")
public class PaymentService {


    public String paymentInfo_OK(Integer id){
        return "线程:"+Thread.currentThread().getName()+"\tpaymentInfo_OK\tid:"+id+"\tO(∩_∩)O哈哈~";
    }

    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "500")
    })
    public String paymentInfo_TimeOut(Integer id){
        long time = 5000;
        try {
            TimeUnit.MILLISECONDS.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "线程:"+Thread.currentThread().getName()+"\tpaymentInfo_TimeOut\tid:"+id+"\t/(ㄒoㄒ)/~~耗时(ms):"+time;
    }

    public String globalFallBack(){
        return "global fall back!!!!";
    }
}
